package com.xiaomiMall.mange.service.Impl;

import com.xiaomiMall.mange.domain.*;
import com.xiaomiMall.mange.mapper.XiaoMiHeaderMapper;
import com.xiaomiMall.mange.service.XiaoMiHeaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class XiaoMiHeaderServiceImpl implements XiaoMiHeaderService {

    @Autowired
    private XiaoMiHeaderMapper xiaoMiHeader;

    @Override
    public List<XiaoMiTop> selectXiaoMiTop() {
        return xiaoMiHeader.selectXiaoMiTop();
    }

    @Override
    public List<XiaoMiNav> selectXiaoMiNav() {
        return xiaoMiHeader.selectXiaoMiNav();
    }

    @Override
    public List<XiaoMiNavPic> selectXiaoMiNavPic() {
        return xiaoMiHeader.selectXiaoMiNavPic();
    }

    @Override
    public List<Cart> selectProId(Long prodId, String prodVersion) {
        return xiaoMiHeader.selectProId(prodId,prodVersion);
    }

    @Override
    public int addCart(Long userId, Long detail_uid) {
        return xiaoMiHeader.addCart(userId,detail_uid);
    }

    @Override
    public List<ShoppingCart> selectAll(Long userId) {
        return xiaoMiHeader.selectAll(userId);
    }

    @Override
    public boolean updateNumber(Long amount,Long id) {
        return xiaoMiHeader.updateNumber(amount, id);
    }

    @Override
    // 此方法开启异步
    @Async
    public Integer deleteCart(List<Long> ids) {
        synchronized (ids) {
            Integer i = xiaoMiHeader.deleteCart(ids);
//            System.out.println("已删除该购物车");
            return i;
        }
    }

    @Override
    public int deleteCart(Long id) {
        List<Long> ids = new ArrayList<>();
        ids.add(id);
        return xiaoMiHeader.deleteCart(ids);
    }

}
